package com.ruoyi.course.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.Courses;
import com.ruoyi.course.service.ICoursesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程详情管理Controller
 * 
 * @author gzq
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/course/courses")
public class CoursesController extends BaseController
{
    @Autowired
    private ICoursesService coursesService;
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    /**
     * 查询课程详情管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:courses:list')")
    @GetMapping("/list")
    public TableDataInfo list(Courses courses)
    {
        startPage();
        List<Courses> list = coursesService.selectCoursesList(courses);
        return getDataTable(list);
    }

    /**
     * 导出课程详情管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:courses:export')")
    @Log(title = "课程详情管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Courses courses)
    {
        List<Courses> list = coursesService.selectCoursesList(courses);
        ExcelUtil<Courses> util = new ExcelUtil<Courses>(Courses.class);
        util.exportExcel(response, list, "课程详情管理数据");
    }

    /**
     * 获取课程详情管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courses:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(coursesService.selectCoursesById(id));
    }

    /**
     * 新增课程详情管理
     */
    @PreAuthorize("@ss.hasPermi('course:courses:add')")
    @Log(title = "课程详情管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Courses courses)
    {
        return toAjax(coursesService.insertCourses(courses));
    }

    /**
     * 修改课程详情管理
     */
    @PreAuthorize("@ss.hasPermi('course:courses:edit')")
    @Log(title = "课程详情管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Courses courses)
    {
        return toAjax(coursesService.updateCourses(courses));
    }

    /**
     * 删除课程详情管理
     */
    @PreAuthorize("@ss.hasPermi('course:courses:remove')")
    @Log(title = "课程详情管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(coursesService.deleteCoursesByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('course:courses:list')")
    @GetMapping("/Detail")
    public TableDataInfo Detail(Courses courses,
                                @RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "8") Integer pageSize) {

        startPages(pageNum, pageSize);
        List<Courses> list = coursesService.selectVideoDetail(courses);
        System.out.println("changdu" + list.size());
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('course:courses:list')")
    @GetMapping("/Host")
    public TableDataInfo Host(Courses courses)
    {
      List<Courses> list = coursesService.selectHost(courses);
        System.out.println("changdu"+list.size());
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('course:courses:list')")
    @GetMapping("/Detail/{id}")
    public AjaxResult DetailId(@PathVariable("id") Integer id)
    {
        return success((coursesService.selectDetailById(id)));
    }
}
